package com.hbsi.demo1;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @author 程奕红
 * @version 1.0
 */
public class Test2JDBC {
    public static void main(String[] args) throws SQLException, ClassNotFoundException {
            getAllInformation();
    }
    public static  void getAllInformation() throws ClassNotFoundException, SQLException {
        //1.载入驱动
        Class.forName("com.mysql.jdbc.Driver");
        //2.建立连接
        String url="jdbc:mysql://localhost:3306/javaTest";
        String username="root";
        String password="root";
        Connection connection= DriverManager.getConnection(url,username,password);
        System.out.println(connection);
        //3.创建Statement对象，执行sql语句
        Statement statement=connection.createStatement();
        int rows=statement.executeUpdate("insert into Scores values(1,'熊大',99.5)");
        if(rows>=0){
            System.out.println("执行语句成功，成功执行了"+rows+"语句");
        }else{
            System.out.println("执行语句失败");
        }
        //4.关闭连接---关闭对象
        if(statement!=null){
            statement.close();
        }
        if(connection!=null){
            connection.close();
        }
    }
}
